package com.yiren.dbaa.module.practice_set.carmodel.presenter;

import android.app.Activity;

import com.yiren.backstage.currency.entity.CarModelEntity;
import com.yiren.dbaa.currency.api.CommonCallBack;
import com.yiren.dbaa.module.practice_set.carmodel.contract.CarModelManageContract;
import com.yiren.dbaa.module.practice_set.carmodel.model.CarModelManageModel;
import com.yiren.dbaa.module.practice_set.line.contract.LineManageContract;
import com.yiren.dbaa.view.toast.MessageBox;

/**
 * @author lwb
 * @date : 2022/12/6 14:43
 * @description: 车模管理
 */
public class CarModelManagePresenter implements CarModelManageContract.Presenter {

    private Activity activity;
    private CarModelManageContract.Model manageModel;

    public CarModelManagePresenter(Activity activity) {
        this.activity = activity;
        manageModel = new CarModelManageModel(activity);
    }

    @Override
    public void changeUserRange(CarModelManageContract.View view, CarModelEntity carModel, int range) {
        manageModel.updateUserRange(carModel, range, new CommonCallBack() {
            @Override
            public void success(Object result) {
                //本地修改
                manageModel.updateUserRangeLoacl(carModel, range);
                activity.runOnUiThread(() -> view.updateUseRange(range));
                MessageBox.show(activity, "更改成功!");
            }

            @Override
            public void fail(String error) {
                MessageBox.show(activity, error);
            }
        });


    }
}
